package org.groupg.practice.configuration;

import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.ex.ConfigurationException;

import java.io.*;
import java.nio.file.Files;

public class PropertiesFileExample {
    public static void main(String[] args) {
        try {
            // 创建 PropertiesConfiguration 对象，并加载配置文件
            PropertiesConfiguration config = new PropertiesConfiguration();

            config.read(new FileReader(ClassLoader.getSystemResource("db.properties").getFile()));
            // 获取配置项的值
            String jdbcUrl = config.getString("jdbc.url");
            String username = config.getString("jdbc.username");

            // 输出配置项的值
            System.out.println("JDBC URL: " + jdbcUrl);
            System.out.println("Username: " + username);
        } catch (ConfigurationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}